home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Multimedia & Desktop / gst-torque-demo / Torquemada Explained / Torquemanual < prev    next >
Text File  |  1992-05-27  |  45KB  |  1,055 lines

  1.  
  2.  
  3.  
  4.  
  5. A Torquemanual for the Inquisitive
  6.  
  7.  
  8.  
  9.  
  10. Documenting Torquemada version 1.1.0, © 1992 by Greg Swann
  11.  
  12. 5/27/92
  13.  
  14. Greg Swann
  15. CompuServe: 70640,1574
  16. USPS: P.O. Box 1724
  17. Andover, MA 01810
  18.  
  19.  
  20.  
  21.  
  22. Table of Disorganization
  23.  
  24. 0. Introductory Chatter
  25.  
  26. 1. Torquemada Basics
  27.  
  28. 2. String Literals
  29.  
  30. 3. Aliases
  31.  
  32. 4. Case Conversion
  33.  
  34. 5. Untyped Wildcards
  35.  
  36. 6. Typed Wildcards
  37.  
  38. 7. Wildstrings
  39.  
  40. 8. Putting It All Together
  41.  
  42. 9. Bringing It All Back Home
  43.  
  44.  
  45.  
  46. 0. Introductory Chatter
  47.  
  48. This is kind of a funny little Ugly Duckling story. Torquemada the
  49. Inquisitor started life as a fluffy little bit of nothingstuff with a
  50. Mac interface wrapped around it. When we were testing XP8, Garry
  51. Fairbairn (the Argus of Saskatoon) had asked me to come up with a
  52. search and replace engine that he could use to translate American
  53. spellings to those favored by people more recently divorced from the
  54. Crown. I came home one night and spent two minutes writing a little
  55. toy that traded massive quantities of memory for very, very fast
  56. searches. That little core was the basis of the first Torquemada.
  57.  
  58. Torquemada 1.0.0 worked only on string literals. It sported no
  59. wildcards. It read only only one line at a time. But it was very,
  60. very fast...
  61.  
  62. We've been through ten versions since then. Along the way, the
  63. search engine has been replaced twice, making it somewhat slower but
  64. a lot less hungry for memory. The read/write code has been replaced
  65. three times. The interface has been (transparently) overhauled. And
  66. somewhere in there, I began to take it seriously... (grin)
  67.  
  68. The current release, version 1.1.0, can deploy up to 640 search and
  69. replace strings on up to 128 files in a drag and drop batch, and the
  70. searches can employ up to 29 wildthings of various stripes
  71. ("wildthings" are Torquemada's multifaceted wildcards; there will be
  72. _much_ more about these in due course). And it is still very, very
  73. fast...
  74.  
  75. And this is very far from the end of the story. But it is the end for
  76. now, which makes this the appropriate place to fully document the
  77. software as it now stands. Torquemada 2.0 will offer a great host of
  78. new features, but it will not go into development for some while. In
  79. the interim, I didn't want to leave users puzzling over ten sets of
  80. release notes scattered in four separate files.
  81.  
  82. But: as a warning: I am not very good at this (witness my performance
  83. so far (grin)). My feeling is that writing technical documentation is
  84. something best done by someone other than the programmer, someone who
  85. had to _learn_ the answers to questions, and who had to remember that
  86. process of discovery. I'll do my best to do a full brain-dump, but I
  87. don't promise that the results will be clear to anyone but myself.
  88.  
  89.  
  90. Commercial, legal and other pertinent notices:
  91.  
  92. XP8 is a text file reformatter. It will clean up and make
  93. QuarkXPress-ready Macintosh or DOS text files. Among many other
  94. features, it intelligently reformats paragraphs, converts the DOS or
  95. WordStar character sets to their Mac equivalents, substantially
  96. improves the hyphenation and justification of text, converts quotes
  97. better than any software currently available, and traps for XPress
  98. Tags errors that might otherwise result in missing text or
  99. irreversible document corruption. A semi-inhibited shareware version
  100. of XP8 is available on CompuServe (GO DTPFORUM, Library 5) and other
  101. electronic information services. The full commercial release can be
  102. obtained from Greg Swann at:
  103.  
  104. P.O. Box 1724
  105. Andover, MA 01810
  106.  
  107. Licenses are sold per machine, with a single license costing $50;
  108. 2-10 licences are $45 each; and 11 or more licenses are $40 each.
  109.  
  110. Torquemada is freeware in its current release. Torquemada 2.0 will be
  111. a commercial release, and it will be priced in the same range as is
  112. XP8.
  113.  
  114. Torquemada is delivered "as is", without any warranties, expressed or
  115. implied. It is not warranted to be useful _to_ anyone, _for_
  116. anything, and in no wise am I to be held responsible for any
  117. unfortunate consequences resulting from its use or misuse. And I
  118. _hate_ having to say things like that. I do my best to write useful,
  119. simple, elegant, bug-free solutions to difficult problems. In this
  120. case, I am giving of my labor at no charge at all. If you take it
  121. into your head that I represent your big chance to 'strike it rich,'
  122. you will pay a lot in legal fees to discover that you have
  123. miscalculated. It's sad and sick and stupid that we live in a world
  124. of bloodsuckers, but I _promise_ I will not be leech lunch. So there!
  125.  
  126. And: to those to whom the above disclaimer does not apply: forgive me
  127. for having to make it. It's _you_ whom I'm working for, for pay or for
  128. free. I appreciate your custom and your support, and I wish we all
  129. could just comb the others out of our hair...
  130.  
  131. (Hey, it's a real 'personal' software company! (grin))
  132.  
  133.  
  134. Some notes at random:
  135.  
  136. While XP8 is a QuarkXPress-specific program, Torquemada can be used
  137. with any Macintosh software that can read and write files of type
  138. TEXT (plain text files). For that reason, this manual is produced as
  139. a plain text file. I would much prefer to write it as an XPress file,
  140. but that wouldn't be terribly useful to people using PageMaker,
  141. ReadySetGo! or FrameMaker. For ease of use with a variety of text
  142. editors, this file is produced in DOS-like fashion; each line ends
  143. with a carriage return. Ideally, you should read it and print it out
  144. in a monospaced font such as Courier, since in certain places things
  145. are aligned with spaces. And: where a certain keystroke might be
  146. ambiguous, I am naming it in words enclosed in braces; for example,
  147. {space} means the spacebar character.
  148.  
  149. In the same neighborhood, because I myself am an XPress user, and
  150. because my own uses for Torquemada are focused on Quark, my examples
  151. tend to be intensely Quark-like. This is a side-effect that will have
  152. to be overcome by users of other software. Reasoning by analogy, you
  153. will be able to see how to apply my examples to similar features in
  154. your software of choice.
  155.  
  156. To make the best use of this software (and of XP8, for that matter),
  157. you need some type of fairly functional text editor/word processor. I
  158. use Word or BBEdit, a freeware programmer's editor. The latter is
  159. highly recommended for our purposes.
  160.  
  161. As mentioned above, Torquemada owes its origins to some exceptionally
  162. literate caterwauling by Garry Fairbairn. Its further development was
  163. goaded in good measure by some very compelling growling by Shane
  164. Stanley (who has a unique perspective on things due to his insistence
  165. on living upside down in an entirely different day). Along the way, a
  166. number of other users made valid, valuable suggestions, and I'm sure
  167. that will continue to be the case. More than any other piece of
  168. software by me, Torquemada has been influenced by its users, and,
  169. here, at the outset, I want to encourage you to contact me with any
  170. requests or suggestions you have.
  171.  
  172. The default "Torquemada Prefs" file shipped with this archive pays
  173. homage to the 20 brave souls who lent their diligence and
  174. intelligence to the XP8 beta-testing process. Despite my gentle
  175. ribbing, they have my gratitude and my highest respect.
  176.  
  177. Mike Arst (inventor of the Kvetchamatic Irregular Expression Parser)
  178. had a profound and lasting impact on this document. Obviously, any
  179. remaining errors or ambiguities are my responsibility; he takes
  180. credit only for the stuff that is clear, grammatically correct, and
  181. spelled properly in languages currently in use by humans. Seriously:
  182. he has a rare talent for inducing a tabula rasa mental state (this
  183. may not be a compliment!), such that he can spot hand-waving or other
  184. logical elisions better than anyone I know. It was he who forced me
  185. to write the (to me tedious) descriptions of what each and every
  186. command means. If you are a software developer, you are well-advised to
  187. pay Mike whatever he asks to critique your documentation. He can be
  188. reached on CompuServe at 70403,1337 or by USPS at:
  189.  
  190. Mike Arst
  191. 2459 Fifth Avenue West
  192. Seattle, WA 98119-2506
  193.  
  194. Perhaps because of its democratic roots (how odd for a program named
  195. after an autocrat), Torquemada the Inquisitor has sprouted a great
  196. host of nicknames. I tend to call things by (quasi-)acronym, so he's
  197. TQM to me. From the very beginning he was Torque or Tork to others,
  198. and these gave rise to verb forms: I Torque, you were Torking, they
  199. had Torqued.
  200.  
  201. And, for reference: Tomas de Torquemada was the First Grand
  202. Inquisitor of the Spanish Inquisition. The name was later adopted as
  203. a nom de guerre by the first editor of the Sunday Times of London
  204. Crossword Puzzle, and I probably would not have used it were it not
  205. for that latter association.
  206.  
  207.  
  208.  
  209. 1. Torquemada Basics
  210.  
  211. Torquemada is: 32-bit clean, System 7 compatible, Multi-Finder eager,
  212. Apple Event aware, kind to children and house pets, and safe for use
  213. on your precious hardwood floors.
  214.  
  215. Torquemada will run on any Mac from the Plus up. It requires 768K of
  216. RAM, and you are cautioned not to set the partition smaller than
  217. this; we're using it all.
  218.  
  219. The interface consists of two dialog boxes and two help windows, and
  220. all of these are very straightforward in operation. If you can use a
  221. Mac at all, you can use my boy Torque.
  222.  
  223. The Pyre of Purification dialog box uses 10 point Helvetica. If you
  224. don't have that bitmap loaded, you will need to load it into either
  225. your System file or your Core Fonts suitcase. If you don't, Torquemada
  226. will still work, but the search and replace strings will be hard to
  227. read.
  228.  
  229. And: when your files are being processed, Torque displays the stylish
  230. and attractive Movado Museum Watch Cursor to let you know that things
  231. are really happening.
  232.  
  233. TQM reads files of type 'TEXT'. It will also see files with the
  234. creator types 'text', 'MDOS', 'mdos', 'CRLF' and 'crlf'. These latter
  235. types are supported because some third-party products have very odd
  236. ideas about how to treat 'TEXT' files.
  237.  
  238. Torquemada writes files of type 'TEXT' (with the creator type
  239. 'XP84'). These files can be opened from any application that can read
  240. plain text files. They can be processed directly by XP8 or other
  241. utilities of mine. Or they can be imported directly into QuarkXPress,
  242. PageMaker or any other publishing application with a plain- or
  243. smart-ASCII filter.
  244.  
  245. You write your search and replace strings into the Pyre of
  246. Purification dialog box. Searches go on the left and replaces on the
  247. right. Space is allotted for up to 20 search and replace strings, and
  248. precious little space is left on a nine-inch screen! Torquemada
  249. search and replace strings have an enormous maximum length (254
  250. characters). The normal Macintosh text editing services are available
  251. in the Pyre, along with Select All, Copy, Cut, Paste and Clear. You
  252. can Copy from your text editor and Paste into the Pyre, which is the
  253. fastest way to write search strings.
  254.  
  255. The Inquisitor reads and writes sets of search and replace strings.
  256. This is valuable: in many cases, you need to perform the same
  257. searches on the same types of files, week in and week out. Once you
  258. have perfected a set of searches, you can save it for reuse. Through
  259. the Load Set button in the Pyre of Purification dialog box,
  260. Torquemada will read set files having the creator type 'PREF'. It
  261. will also 'see' the types 'pref', 'TEXT', 'text', 'CRLF' and 'crlf'.
  262. These latter types are supported so that, if you want, you can write
  263. sets in your word processor. A TQM set consists of 40 plain text
  264. lines in the form of search, replace, search, replace, etc. When you
  265. hit the Save Set button in the dialog, the software will write the
  266. currently active set to a file of type 'PREF'.
  267.  
  268. If you have one basic set of searches that you frequently need to
  269. run, you can save it under the name "Torquemada Prefs" and store it
  270. in the same folder where TQM resides. When you launch the software
  271. directly, this set will load automatically.
  272.  
  273. Alternatively, you can launch Torquemada by double-clicking on a set,
  274. by selecting it and doing a Finder Open, or (under System 7) by
  275. dragging the set onto the application's icon or an alias of it.
  276. Torque will launch and the set you selected will be loaded
  277. instead of Torquemada Prefs. For this to work, the set must have the
  278. creator type 'PREF'.
  279.  
  280. You can select up to 32 sets (of type 'PREF') in this fashion, and
  281. the sets will be processed in alphabetical order on your text files.
  282. This gives you up to 640 search strings per session, surely enough
  283. for anyone. These sets will persist until you either Quit, Load Set,
  284. Save Set or Clear All. After you do any of the latter three, only the
  285. set visible in the Pyre of Purification will be run on your text.
  286.  
  287. Under System 7, you can select up to 128 text files and drag and drop
  288. them onto the application's icon or an alias of it. At the same time,
  289. you can drag and drop up to 32 sets (of type 'PREF'). If you do not
  290. select any sets, Torquemada Prefs will be run on your batch of files.
  291. If you do select one or more sets, those sets will be run in
  292. alphabetical order on each of your files.
  293.  
  294. To make this clear:
  295.  
  296. You can use the standard file interface to Load Sets and Open and
  297. Save files; or,
  298.  
  299. You can select a number of sets in the finder and use the standard
  300. file interface to have those sets run in alphabetical order on each
  301. file Opened; or,
  302.  
  303. Under System 7, you can select a number of sets and a number of files
  304. and drag and drop them all on Torque. Each file will be run against
  305. all the sets. 
  306.  
  307.  
  308. Not for nerds only:
  309.  
  310. 'Alphabetical order' is serious business. The 'natural' order is the
  311. order selected (clicked upon) in the Finder. That's hard to remember,
  312. and it's hard to predict the effects of multiple file selection done
  313. by dragging out a marquee. So: we're sorting to lexical order: A
  314. comes before Z, which comes before a, which comes before z. The files
  315. 'Today', 'TODAY', and 'today' would sort to:
  316.  
  317. TODAY
  318. Today
  319. today
  320.  
  321. O comes before o, and T comes before t. If you need to know how sets
  322. will sort, just look at an ASCII chart. Better yet, name your sets
  323. with numbers; use two digits (02, not 2), since 10 comes before 2.
  324.  
  325. Why are we sorting sets? A batch of sets is a 'virtual' set. The
  326. second search in a single set can operate on the results of the first
  327. search. In the same way, the first search in the second set of a
  328. batch can operate on something left behind by the first set. To use
  329. batches of sets reliably, you have to know the exact order in which
  330. the searches will be made. Sorting the sets gives you greater
  331. control.
  332.  
  333. Why are the file limits set so high? Because I hate to think that
  334. anything I do is _almost_ good enough. Honestly, if ever you find
  335. yourself running 640 searches, examine your methods to see if they
  336. can be made more general. If ever you find yourself running on a
  337. batch of 128 files, query your source to see if they can tighten up
  338. on their end a bit. But: if you really _do_ need awesome quantities
  339. of strings or files, you've got 'em.
  340.  
  341. Batch-processed files will have the default extension (.TQM) applied
  342. to them automatically. If a source file has already been Torqued, and
  343. if its name is _exactly_ 31 characters in length, the new name would
  344. be identical to the old. In that one case, we are using a slightly
  345. different extension (.TQµ), so as to avoid toasting the source file.
  346.  
  347. Logic of Beeps: if you run a batch of files, Torquemada will beep at
  348. you, a cheery little, "Hey, Dufus! Wake up!" TQM also beeps at the
  349. end of any _normal_ run that takes longer than 5 seconds.
  350.  
  351.  
  352. Nuts and bolts:
  353.  
  354. Torquemada reads and writes by the buffer-load. At read time, a
  355. buffer is approximately 16K in size, and space is allocated for a
  356. buffer to quadruple in size during processing. Torque can read around
  357. returns _because_ it is working on these enormous buffers. At the
  358. same time, we divide between buffers intelligently, so as to avoid
  359. missing any searches.
  360.  
  361. At the time that a new buffer is assembled, a check is run against
  362. the end of the buffer. If any of the search strings are present in
  363. the end of the buffer, the buffer is truncated at the start of the
  364. earliest full match. The remainder is prepended to the next buffer.
  365.  
  366. Each search string is run against the whole buffer _as it is at the
  367. time of the search._ Consequently, later searches can operate on the
  368. results of earlier replaces. This proves useful on a number of
  369. grounds, as we will see in due course. But it is also grounds for a
  370. certain amount of caution.
  371.  
  372. The buffer truncation mentioned above can only happen with strings
  373. that represent the literal contents of the source file at read time.
  374. So if a later search needs to find something put in by an earlier
  375. replace, that earlier search needs to include everything expected by
  376. the later search. As an example, this could fail ("^p" is a Torquemada
  377. 'alias' that denotes the carriage return character):
  378.  
  379. ^pGreg          ^p<B>Greg<B>
  380. ^p^p<B>Greg<B>  ^p^p<BI>Greg<BI>
  381.  
  382. It could fail because the first search doesn't require Torquemada to
  383. preserve both returns in the same buffer. In a very large file, with
  384. a large number of chances to fail, some few can slip the cracks. The
  385. solution is simple: specify everything you'll need to see in search
  386. strings that reflect the actual contents of the file:
  387.  
  388. ^p^pGreg        ^p^p<B>Greg<B>
  389. ^p^p<B>Greg<B>  ^p^p<BI>Greg<BI>
  390.  
  391. Torquemada uses 29 characters in low ASCII for its own storage
  392. purposes; all of the various wildthings are flagged with these codes.
  393. In consequence, the software needs to insulate any low ASCII characters
  394. found in the source. Otherwise, they would look like wildthings during
  395. searches. So at read time, Torquemada is converting low ASCII found in
  396. the source to a relatively harmless form, e.g. <\#008>. ASCII 1 though
  397. 8, 11, 12, and 14 through 29 are handled this way.
  398.  
  399. ASCII 10 (the linefeed) is handled with a certain measure of
  400. intelligence. The linefeed is the poor relation among control
  401. characters. It had a great day in the sun on Unix systems, where its
  402. use is analogous to the carriage return on the Mac. On DOS systems,
  403. it is an entirely redundant siamese twin to the carriage return. And
  404. on Macs, the poor little linefeed isn't used at all. So: if
  405. Torquemada finds himself processing a Unix file, he will convert the
  406. linefeeds to carriage returns. Linefeeds in DOS files are thrown away
  407. with malice aforethought.
  408.  
  409. ASCII 9 and 13 (Tab and Return) are not converted.
  410.  
  411. ASCII 30 is used by Word to denote non-breaking words, so we're
  412. converting that to <\h>, the XPress Tags-language mnemonic for "don't
  413. hyphenate". And Word uses ASCII 31 for the non-breaking hyphen, so
  414. we're showing that as <\!#45>, XPress Tags for a non-breaking hyphen.
  415. All of these conversions happen before any searches are run, so you
  416. can search for the rare instance of low ASCII by using these codes.
  417.  
  418.  
  419.  
  420. 2. String Literals
  421.  
  422. The simplest use that can be made of Torquemada is to search for
  423. string literals. This means literal text that actually appears in the
  424. source file. For example, you could search for "Elvis" and replace
  425. with "The King". If "Elvis" is present in the file, the replacement
  426. will be made. Torquemada searches are case sensitive, which means
  427. that if "elvis" or "ELVIS" are found in the file, the replacement
  428. will not be made.
  429.  
  430. String literal searching is common; most applications that have a
  431. search and replace function work only on string literals. Used this
  432. way, TQM offers not much more than they, except that you can search
  433. for 20 (or 640!) string literals at once.
  434.  
  435. But consider: residents of British Commonwealth nations have a tough
  436. way to go when they try to use text written in the United States. A
  437. massive batch of string literals can be just the ticket.
  438.  
  439. And: string literals help to establish uniqueness in search strings
  440. that employ wildthings of various stripes. (I'm not sure I really
  441. have to say this, so I'd better.) Uniqueness means taking pains to be
  442. sure that a search finds only those particular strings you want
  443. changed, and not others. For example, our Queen's English-speaking
  444. friends might want to change color and favor to colour and favour.
  445. They might write the literal search:
  446.  
  447. or              our
  448.  
  449. This is pretty drastically non-unique. It would change the two
  450. desired words, but it would also change the name of this software to
  451. Tourquemada.
  452.  
  453. Uniqueness is one of those things that can only be learned the hard
  454. way. So if the idea is new to you, spend half a day playing with
  455. copies of files.
  456.  
  457.  
  458.  
  459. 3. Aliases
  460.  
  461. ALIASES—Match special text characters
  462.   ^T or ^t    Tab
  463.   ^P or ^p    Carriage return
  464.   ^^          Caret
  465.  
  466. You can't type a tab or a return in a dialog box. The Mac toolbox
  467. filters for these characters, regarding them as commands. Tab moves
  468. you from field to field, while hitting return is the same as clicking
  469. the mouse on the Okay button. This is hardly news.
  470.  
  471. If you want to search for one of these characters, you have to use an
  472. 'alias' of it. Torquemada uses Word's convention for denoting these
  473. aliases: tab is known as ^t or ^T, and return is wanted in five
  474. states under the name ^p or ^P. The caret character is used to flag
  475. all of Torque's many wildthings, so it too should be aliased in
  476. search and replace strings: ^^. The caret is ideal for our purposes,
  477. since it almost never appears in text.
  478.  
  479. Take note that you _can_ Paste tabs and returns into a dialog box. If
  480. you do, Torquemada will behave as you expect (since the aliases are
  481. just being turned into the literal tab and return characters at
  482. search time). When you Save Set, a clean-up is run that converts any
  483. Pasted tabs or returns into their aliased form.
  484.  
  485.  
  486.  
  487. 4. Case Conversion
  488.  
  489. CASE CONVERSION COMMANDS—Can be used only on the replace side;
  490.                          accented characters are handled
  491.                          intelligently
  492.   ^C or ^c    CONVERT TO ALL CAPS
  493.   ^L or ^l    convert to all lower case
  494.   ^S or ^s    Convert to sentence caps
  495.   ^U or ^u    Convert To Upstyle Caps
  496.   ^D or ^d    Convert to Downstyle Caps
  497.   ^=          Cancel all case conversion
  498.  
  499. Torquemada includes six case conversion commands that are available
  500. on the replace side only. If your source text is typed ALL CAPS, you
  501. can convert it to sentence caps fairly easily. The commands can be
  502. used only on the replace side because they control the output format
  503. of the text found; they are not themselves something that can be
  504. searched for. If you forget and put one in on the search side, TQM
  505. will cheerfully ignore it with no untoward consequences.
  506.  
  507. But: case conversion by software is far from an exact science. The
  508. commands will get you closer to where you want to be, but you may
  509. have to run additional searches or do manual edits to achieve the
  510. final desired results. This is particularly true of sentence caps and
  511. downstyle caps (first letter of every word capitalized, except for
  512. words of three or fewer letters).
  513.  
  514. However: Torquemada is pretty smart. If your text is totally toasted,
  515. using these commands will save you a _lot_ of time. And the
  516. Inquisitor is a good global citizen: accented characters are
  517. converted appropriately. Moreover, Torque knows when to say when.
  518. Quark's XPress Tags language is case-sensitive ('k' and 'K' mean two
  519. different things). Only one of XP8's commands is case-sensitive. But
  520. in both cases, we're insulating those commands from case conversion.
  521.  
  522. Face it: a file that is typed _all_ in the wrong case is the rare
  523. bird. Further on, we'll see how to use these commands in conjunction
  524. with other wildthings to selectively change case. For example, you
  525. could take just the subheads to ALL CAPS, or change any ALL CAPS
  526. headline to Upstyle Caps. For now, we'll just talk about using these
  527. with string literals. This search:
  528.  
  529. Elvis           ^CElvis^=
  530.  
  531. would result in the word "ELVIS" being written out to the file. In
  532. the replace string, ^C means convert to all caps, and ^= means cease
  533. to convert case. (Of course, a search this simple could be done simply
  534. with literals.) You don't need to use ^= if it is the last thing in
  535. the replace string; Torque will put one there if it doesn't find one.
  536. On the other hand, if you need to terminate case conversion _within_
  537. the replace, then you must explicitly turn it off:
  538.  
  539. Elvis is still the king         ^CElvis^= is still ^Uthe king
  540.  
  541. would result in the text "ELVIS is still The King". We turned
  542. capitalization off after "ELVIS" to avoid changing the case of "is
  543. still". We didn't need to turn upstyle off, since it will be
  544. terminated automatically at the end of the replace string.
  545.  
  546.  
  547.  
  548. 5. Untyped Wildcards
  549.  
  550. UNTYPED WILDCARDS—Match any one character
  551.   ^0, ^1, ^2, ^3, ^4, ^5, ^6, ^7, ^8, ^9
  552.  
  553. Okay, this is where the bullet hits the bone. I've been dancing
  554. around this for quite a while, because I wanted to establish good
  555. ground rules before we got to the more hirsute topics. Well, here we
  556. are...
  557.  
  558. Torquemada has (count 'em) 10 untyped wildcards. 'Wildcards' means
  559. they are not literal characters, but rather markers that will match
  560. literal characters. 'Untyped' means they will match _any_ character.
  561. In Word, '?' is a wildcard, but it can only be used on the search
  562. side. Torquemada's wildcards can be used on the search side, and can
  563. be used, omitted or resequenced on the replace side. Torquemada's
  564. untyped wildcards are denoted by the caret character followed by
  565. a number from 0 to 9. Each one of them will match any character
  566. and _store_ the character matched. Taking our earlier example:
  567.  
  568. ^0^1^2or        ^0^1^2our
  569.  
  570. will match and change color and favor. Unfortunately, it still lacks
  571. uniqueness. Because these wildcards are totally untyped, the search
  572. string will also match any instance of the letters "or" and the three
  573. characters before it.
  574.  
  575. Here's a better example. Suppose we have text that looks like this:
  576.  
  577. 1. Blah.
  578. 2. Blah blah.
  579. 3. Blah. Blah blah.
  580.  
  581. If we needed to modify this, say to add a Quark 'Indent Here' command
  582. to make sure that blahish turnovers hang on the indent, we could do:
  583.  
  584. ^p^0.{space}    ^p^0.{space}<\i>
  585.  
  586. Surely we could do this with literals, but that would get tiresome.
  587. Instead, we can use our knowledge to carefully control ignorance, and
  588. accomplish in one string what might otherwise take three. Note that
  589. we are isolating to uniqueness the text we hit; without the ^p and
  590. the {space}, '^0.' would also match the ends of sentences.
  591.  
  592. Perhaps the best use of untyped wildcards is as ballast for the typed
  593. wildcards (to be discussed next). They do what they do alone quite
  594. well, but it's almost too much ignorance safely to be borne.
  595.  
  596.  
  597.  
  598. 6. Typed Wildcards
  599.  
  600. TYPED WILDCARDS—Match any one character of that type
  601.   ^+    Uppercase character (includes accented characters)
  602.   ^-    Lowercase character (includes accented characters)
  603.   ^±    Character of either case (includes accented characters)
  604.   ^&    Alphanumeric character (letter or number, not space or punctuation)
  605.   ^%    Tabular character (digit, space or punct.; not alphabetical)
  606.   ^$    Printable character (all characters _except_ space characters)
  607.   ^!    Punctuation character (includes high-ASCII punctuation)
  608.   ^#    Numeric character (digits only)
  609.   ^_    Space character (space, return, tab, option space)
  610.  
  611. These are alike unto the untyped wildcards except that they are
  612. strongly typed. A typed wildcard will only match a character of its
  613. type. So, for instance: ^+ will only match uppercase characters, with
  614. all others failing to match. The wildcard ^# will match any digit,
  615. and ^_ will match any space character, so we can go back to blahville
  616. and do a much better job:
  617.  
  618. ^p^#.^_         ^p^#.^_<\i>
  619.  
  620. This is now fully generalized yet completely unique. If there is a
  621. subtopic such as:
  622.  
  623. a. Subblah.
  624.  
  625. it will fail to match. If we need to do something different with
  626. that, we can match it with another, different string.
  627.  
  628. But: wildcards (typed or untyped) match and store only _one_
  629. character. If you search for:
  630.  
  631. ^#^#
  632.  
  633. only the second digit will be stored. If you need to match and store
  634. two characters of one type, you can use the typed wildcards to
  635. establish uniqueness, then fill out your team with untyped wildcards.
  636. Suppose we needed to match:
  637.  
  638. 10. Double-digit blah.
  639.  
  640. This would work:
  641.  
  642. ^p^#^0.^_       ^p^#^0.^_<\i>
  643.  
  644. Pretty cryptic, not. This says: where you find a return followed by a
  645. digit followed by any other character followed by a period followed
  646. by a space character, soak it all up and spew it back out, appending
  647. an XPress Tags 'Indent Here' command. We've gone from string literals
  648. that were readable but not very useful to _this_, a vitally important
  649. message from space aliens (grin). And it gets worse. In the next
  650. section, we'll discuss an even better - and more cryptic - way of
  651. handling this type of problem.
  652.  
  653.  
  654. Not for non-nerds only:
  655.  
  656. Mike Arst quite correctly pinned me to the mat for not going into
  657. these guys in greater detail. Among the wildthings, these present the
  658. greatest potential for confusion. Untyped wildcards (discussed above)
  659. and wildstrings (discussed below) match _anything_. The typed
  660. wildcards only match characters _of their type__ So: this is a
  661. further elucidation of what "of their type" means.
  662.  
  663. Torquemada is written in the C programming language, and the idea of
  664. typed wildcards is borrowed, analogically, from the character typing
  665. functions available in the standard C function libraries. Where
  666. appropriate, these commands use the full Macintosh character set,
  667. where the C functions do not, but the idea is basically the same. A
  668. typed wildcard matches the source character _if and only if_ the
  669. character is of that type; ^+ will match _only_ uppercase letters,
  670. not lowercase letters, not space or punctuation characters, not
  671. digits.
  672.  
  673. Taking them one by one:
  674.  
  675. ^+    Will match and store any one uppercase alphabetical
  676. character. Alphabetical characters include the accented Macintosh
  677. characters (e.g., Á, Å). This will _fail_ to match any character that
  678. is not an uppercase character.
  679.  
  680. ^-    Will match and store any one lowercase alphabetical
  681. character. Alphabetical characters include the accented Macintosh
  682. characters (e.g., á, å). This will _fail_ to match any character that
  683. is not an lowercase character.
  684.  
  685. ^±    Will match and store any one alphabetical character.
  686. Alphabetical characters include the accented Macintosh characters
  687. (e.g., Á, Å, á, å). This will _fail_ to match any character than is
  688. not an alphabetical character. This wildcard is the logical opposite
  689. of the tabular character wildcard (^%).
  690.  
  691. ^&    Will match and store any one alphanumeric character.
  692. Alphanumeric characters are alphabetical characters (including
  693. accented characters) and the ten digits. This wildcard will _fail_ to
  694. match any space or punctuation character, which can make it useful
  695. for establishing uniqueness.
  696.  
  697. ^%    Will match and store any one tabular character. A tabular
  698. character is any one of the ten digits, a space character (space,
  699. return, tab, or option space), or a punctuation character (including
  700. Macintosh high-ASCII punctuation such as ° or ‡). This wildcard is
  701. intended primarily for matching the elements that make up a table,
  702. exclusive of the explanatory text. Consequently, it will _fail_ to
  703. match any alphabetical character, which can make is useful for
  704. establishing uniqueness. This wildcard is the logical opposite of the
  705. alphabetical character wildcard (^±).
  706.  
  707. ^$    Will match and store any one printable character. A printable
  708. character is one that makes marks on paper, which means that this
  709. wildcard will match all alphabetical characters, all ten digits, and
  710. all punctuation characters. It will _fail_ to match the space
  711. characters (space, return, tab or option space). This wildcard is the
  712. logical opposite of the space character wildcard (^_).
  713.  
  714. ^!    Will match and store any one punctuation character, (including
  715. Macintosh high-ASCII punctuation such as ° or ‡). It will _fail_ to
  716. match alphabetical, numeric, or space characters.
  717.  
  718. ^#    Will match and store any one numeric character (the ten
  719. digits). It will _fail_ to match alphabetical, space, or punctuation
  720. characters.
  721.  
  722. ^_    Will match and store any one space character (space, return, 
  723. tab, or option space). It will _fail_ to match all alphabetical,
  724. numeric, or punctuation characters. This wildcard is the logical
  725. opposite of the printable character wildcard (^$).
  726.  
  727.  
  728.  
  729. 7. Wildstrings
  730.  
  731. WILDSTRINGS—Match and store any text until full pattern is matched
  732.   ^*, ^~, ^?, ^@
  733.  
  734. Now this is the really cool stuff. There are four wildstrings and
  735. each will match and store any text until the pattern defined in the
  736. search string is satisfied. As an example, consider a full case
  737. conversion. You got a file typed in ALL CAPS, and you need it to be
  738. Sentence caps. This will do the job:
  739.  
  740. ^~        ^S^~
  741.  
  742. The search string says: "match anything, from the start of the buffer
  743. to the end." The replace string says, "spew it all back out with the
  744. case converted".
  745.  
  746. A more complicated example: the client was thoughtful enough to
  747. provide the keystrokes on disk, but the heads and subheads are all
  748. typed ALL CAPS (there are many such thoughtful clients). To convert
  749. them all to Upstyle (presuming that the heads to be hit are preceded
  750. by double-returns), you could do:
  751.  
  752. ^p^p^*^p        ^p^p^U^*^p
  753.  
  754. Wildstrings are massively general. Except for gross transformations,
  755. you really have to build a lot of uniqueness into the pattern, or
  756. they will bleed all over you. But try this on for size: I wish I
  757. could count the number of times I've gotten files that were typed
  758. like this:
  759.  
  760. First        Fifth
  761. Second       Sixth
  762. Third        Seventh
  763. Fourth       Eighth
  764.  
  765. In every publishing system known to humanity, this should be typed as
  766. one long column, with fifth following fourth. The helpful clients
  767. type it in two columns with tabs so that you'll know it should be one
  768. link spanning a gutter. Do it the cheap way, with tabs, and surely
  769. you'll have to insert a line between second and third. Have fun
  770. cutting and pasting... Or: run a set like this:
  771.  
  772. ^t^*^p        ^p
  773.  
  774. This will throw away everything in the right column, preserving
  775. everything in the left. Then run:
  776.  
  777. ^p^*^t        ^p
  778.  
  779. This will throw away everything in the left column, preserving the
  780. right.
  781.  
  782. Then concatenate the two files and you've got the text the way you
  783. need it, in one long column.
  784.  
  785. How these work: wildstrings will match and store any characters found
  786. in the source until the full pattern is matched. If the pattern is
  787. matched immediately after the call to the wildstring, it will store
  788. zero characters. This is useful. It means you can say:
  789.  
  790. ^p^~^$        ^p^$
  791.  
  792. This will find all runs of one or more returns (or returns with other
  793. space characters) and compact them down to exactly one return. If the
  794. file has only single returns in it, the wildstring will contain zero
  795. characters each time it is employed.
  796.  
  797. If the pattern fails to match, the text is passed through unaltered.
  798.  
  799. A wildstring can contain the whole buffer of text, as shown above.
  800. Searching for a pattern match will continue to the end of the buffer.
  801. In consequence, insufficient uniqueness can result in failures to
  802. find a match along with very slow performance. So: be sure to deploy
  803. these puppies in full cognizance of the actual contents of the file.
  804.  
  805. Wildstrings are completely untyped, but they can be fairly strongly
  806. 'typed' by the characters used before and after them. Needless to say,
  807. string literals provide the strongest typing, but the more strident
  808. typed wildcards also do very well. The string above that illustrates
  809. how to compact runs of returns is a good example: we are saying
  810. "match everything from a return to a printable character". Printable
  811. characters are characters that are _not_ spaces, so the wildstring is
  812. 'typed' to contain _only_ space characters. A string like this:
  813.  
  814. ^t^%^~^p        ^t<f"e century">^%^~<f$>^p
  815.  
  816. will find the tabular columns of a table (viz., not the text stubs at
  817. the left margin) and plug in XPress Tags coding to change the font.
  818.  
  819. A search string can contain more than one wildstring, up to the full
  820. complement of four. At the same time, wildstrings can be resequenced
  821. on the replace side. So, if that Officers and Directors chart comes
  822. with the jobs before the names, you can swap them.
  823.  
  824. One more (this happened to me this week, and it's happened many times
  825. in the past): pick up last year's financials, lose the right-most
  826. column, kick everything right, and plug in a new column for this
  827. year's figures. Bah! Mondo-beyondo manual labor, even with QuicKeys.
  828. Here's a quick set that does the job on my kind of three-column
  829. table:
  830.  
  831. <t41>^t<t-3>^t^*^t^~^t^?^p        <t41>^t<t-3>^tXX^t^*^t^~^p
  832.  
  833. The "XX" is there to hold the tab, to give the operator something to
  834. double-click on. Yes, the operator had to type the figures;
  835. intelligent hashing is for next week (grin). But: moving the columns
  836. took minutes instead of hours, and the proofreader only had to read
  837. the new copy, not the whole job.
  838.  
  839. There is a _ton_ of power in these babies, so do take the time to
  840. master them, The effort will be repaid a hundred-fold (or a hundred
  841. times your money back! (grin)).
  842.  
  843.  
  844.  
  845. 8. Putting It All Together
  846.  
  847. There is a boatload of Torquemada sets travelling with this document,
  848. to illustrate various points discussed. None of the sets here is
  849. very elaborate, but my feeling is (despite what you may surmise from
  850. reading the DTPForum on CompuServe) the elaborate set is the
  851. exception, rather than the rule. Most search and replace jobs are
  852. fairly simple if they can be generalized to their essence.
  853.  
  854. As an admonition: if this stuff is largely new to you, you are well
  855. advised to take your Torque in small doses. Build the vicious set
  856. that does the worst of the reformatting, then have a look at the
  857. output file. Write a new set to do the finer sifting, then have
  858. another look. There is no shame in having a file named
  859. "file.TQM.TQM.TQM.TQM". The shameful thing would be toasting your
  860. text by trying to do too much at once. My own files tend to be named
  861. "kill.XP8.TQM.XP8.TQM", since I use XP8 to do the gross clean up,
  862. Torque to code for XP8, XP8 to unpack the Torque coding (e.g., I'd
  863. much rather replace with "[n77]" than "<f"univ newswcommpi">M<f$>"),
  864. then Torque, finally, to finesse. What works best is what works
  865. fastest, not the set that wins the Nobel Prize for Cryptic
  866. Communication With Space Aliens (this from the man who came up with
  867. all these cryptic commands!).
  868.  
  869. Here's a brief discussion of the sets enclosed and what they do:
  870.  
  871. 'Stupefaction' uses nothing but string literals and aliases to recode
  872. Mac-like text into a form that can be used on computers less swift.
  873. Ideally, you should reformat the output in an editor (e.g., Save As
  874. Text Only With Linebreaks from Word). That way, those DOS pigs might
  875. actually be able to open the file.
  876.  
  877. 'PC to Mac PostScript' uses literals and one wildstring to clean up
  878. PostScript files that originate on DOS machines but are being
  879. downloaded from Macs. Torquemada automatically removes the linefeeds
  880. (which are not a problem in any case). This set removes other
  881. characters, common in PC-PostScript files, which _can_ be a problem
  882. (most notably the control-D character which starts and ends many
  883. PC-PostScript files).
  884.  
  885. 'Reformat DOS File (Commented)' does the opposite. It takes files
  886. that originated on DOS systems and reformats them to a fairly
  887. Mac-like form. This set is interesting on several grounds. First, it
  888. illustrates how to comment a TQM set: if the search string is empty,
  889. the replace string is ignored. Consequently, you can embed
  890. explanatory comments in your sets simply by typing them into the
  891. replace side. Since you can run up to 32 sets in a batch, this can be
  892. a swell idea: logically separate the types of searches you're
  893. running, then comment each set for future reference. This file is
  894. also making moderately interesting use of wildstrings. And finally,
  895. the set is using markers to permit intelligent processing of special
  896. cases.
  897.  
  898. This warrants its own paragraph: recall that a later search can look
  899. for things left behind by an earlier replace. It is entirely possible
  900. to have a problem complicated enough that you cannot fully resolve
  901. all doubts in one search. In a case like that, you can leave markers
  902. behind (viz., "|" or "][", anything that is unlikely to show up in
  903. the text), then operate on them with later searches. In extreme
  904. cases, you might need to drop in two or more markers, then operate
  905. intelligently on the quantity present when you get around to ditching
  906. them.
  907.  
  908. Or, suppose you get a file in Atari or Commodore ASCII. This seems
  909. unlikely at this late date, but stranger things have happened. The
  910. ASCII in those two systems was swapped: uppercase lived where
  911. lowercase belonged, and vice versa. Presumably this was done for a
  912. reason (to make sorting difficult?), but, whyever, it's a big problem
  913. for you. This set will toggle the case of any file:
  914.  
  915. ^+        |^+
  916.           Mark existing caps
  917. ^-        ^C^-
  918.           Existing lower case to ALL CAPS
  919. |^+       ^l^+
  920.           Marked caps to lower case
  921.  
  922. 'Sentence Caps' shows the first thrust at a very thorny problem.
  923. Suppose you have a file that was typed ALL CAPS. Not all that common,
  924. but it happens. Getting to Sentence caps is fairly easy, but in
  925. getting there, you will have lost most of the caps on proper nouns.
  926. Get set to run a load of literals, because that's the only way to
  927. catch most of them. But at least one can be captured with a
  928. generalized search, as shown in the second search in this set. This
  929. will convert names in the form of Firstname I. Lastname back to
  930. initial caps.
  931.  
  932. 'XP8 to PageMaker®' takes text processed by XP8 or Saved As XPress
  933. Tags from Quark and puts it into a form that can be used by the Smart
  934. ASCII filter in PageMaker. Aldus has promised a smarter Smart ASCII
  935. filter. If you use PM, you might entreat them to hurry, because there
  936. is a lot of cool stuff that can be done with Torquemada if there is
  937. proper support from the destination application.
  938.  
  939. 'Preserve Left Column' and 'Preserve Right Column' are discussed
  940. above.
  941.  
  942. 'Code Alternating Paragraphs' uses wildstrings to code any file that
  943. comes in the form of:
  944.  
  945. A
  946. B
  947. A
  948. B
  949.  
  950. Examples of this type of file: Q&A files, Officers and Directors
  951. tables, phone or store listings, etc. The codes shown are XPress
  952. Tags, but this would work just as well with PageMaker Smart ASCII
  953. tags.
  954.  
  955. 'Code Well-Ordered File' uses wildstrings to code files that come in
  956. the form of:
  957.  
  958. Head
  959. Sub
  960. Body
  961. Sub
  962. Body
  963. Head
  964. Body
  965. Head
  966. Sub
  967. Body
  968.  
  969. The presumption is that headlines and subheads are preceded by
  970. multiple returns, which is usually the case with this type of file.
  971. Note that we are using two different body styles, since frequently
  972. you want to omit the paragraph indent for the first paragraph after a
  973. head.
  974.  
  975. And you can see the point: the judicious use of Torquemada can remove
  976. much of the labor - and certainly the most onerous labor - from a text
  977. processing job. In my own work, I am striving to do everything with
  978. software, with no manual labor at all...
  979.  
  980.  
  981.  
  982. 9. Bringing It All Back Home
  983.  
  984. This is way awesome cool, if I do say so myself (grin).
  985.  
  986. My little ugly duckling has become a text-processing powerhouse.
  987. Six-hundred-forty searches on 128 files with 29 wildthings yields a
  988. solution to all but the most intractable text-processing problems...
  989.  
  990. And this is but barely the beginning! Torquemada 2.0 will include a
  991. host of new features, including:
  992.  
  993. * 50 strings in the Pyre of Purification, split up in five pages. The
  994.   editing area will be twice its current width. Existing sets will be
  995.   compatible, and you will still be able to load up to 32 sets in a
  996.   batch, yielding a total of 1600 strings!
  997.  
  998. * Whitespace characters will be shown as dots for readability.
  999.  
  1000. * GREP-like regular expression parsing (with the existing wildcards
  1001.   still supported)
  1002.  
  1003. * The size of the buffer will be limited only by allocated RAM
  1004.  
  1005. * Control over output file name and creator type
  1006.  
  1007. * Plus some other stuff (grin)...
  1008.  
  1009. In the interim, enjoy my boy Torquemada as he is today, and please do
  1010. not hesitate to contact me with any questions, suggestions or
  1011. problems.
  1012.  
  1013.  
  1014. Very Best!,
  1015.  
  1016. Greg Swann
  1017. 5/14/92
  1018.  
  1019.  
  1020.  
  1021.  
  1022. TORQUEMADA QUICK REFERENCE
  1023.  
  1024. ALIASES—Match special text characters
  1025.   ^T or ^t    Tab
  1026.   ^P or ^p    Carriage return
  1027.   ^^          Caret
  1028.  
  1029. UNTYPED WILDCARDS—Match any one character
  1030.   ^0, ^1, ^2, ^3, ^4, ^5, ^6, ^7, ^8, ^9
  1031.  
  1032. TYPED WILDCARDS—Match any one character of that type
  1033.   ^+    Uppercase character (includes accented characters)
  1034.   ^-    Lowercase character (includes accented characters)
  1035.   ^±    Character of either case (includes accented characters)
  1036.   ^&    Alphanumeric character (not space or punctuation)
  1037.   ^%    Tabular character (digit, space or punct.; not alphabetical)
  1038.   ^$    Printable character (all characters _except_ space characters)
  1039.   ^!    Punctuation character (includes high-ASCII punctuation)
  1040.   ^#    Numeric character (digits only)
  1041.   ^_    Space character (space, return, tab, option space)
  1042.  
  1043. WILDSTRINGS—Match and store any text until full pattern is matched
  1044.   ^*, ^~, ^?, ^@
  1045.  
  1046. CASE CONVERSION COMMANDS—Can be used only on the replace side;
  1047.                          accented characters are handled
  1048.                          intelligently
  1049.   ^C or ^c    CONVERT TO ALL CAPS
  1050.   ^L or ^l    convert to all lower case
  1051.   ^S or ^s    Convert to sentence caps
  1052.   ^U or ^u    Convert To Upstyle Caps
  1053.   ^D or ^d    Convert to Downstyle Caps
  1054.   ^=          Cancel all case conversion
  1055.